package com.awcall.iot.interceptor;

import com.awcall.iot.common.ResponseResult;
import com.awcall.iot.utils.ResponseUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AuthInterceptor extends HandlerInterceptorAdapter {

    private static final Logger log = LoggerFactory.getLogger(AuthInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (request.getAttribute("systemUserId") == null) {
            ResponseUtils.writeJson(new ResponseResult(400, "token为空"));
            return false;
        }

        return true;
    }

}
